Rails Cookbook by Rob Orsini

Rails Cookbook by Rob Orsini

Author:Rob Orsini [Orsini, Rob]
Language: eng
Format: epub
Tags: Xml, Web, Page Design, JavaScript, Ruby (Computer Program Language), Programming Languages, Electronic Books, Programming, Computers, Web Site Development, General, Ruby (Computer Programming Language), Software Development & Engineering, Site Design, Browsers, Internet, Object Oriented, Security, Object-Oriented Programming (Computer Science), Ruby
ISBN: 9780596527310
Publisher: O'Reilly Media
Published: 2007-01-02T08:00:00+00:00


When debugging cookie issues, it is often important to turn on your browser's cookie tracking. Tracking can show you what the cookie actually looks like to the browser. Once you have the actual cookie string, you can pass it back in to the cookie object so your tests are driven by real-world test data.

test/functional/cookie_controller_test.rb:

def test_cookie_from_string cookie_parsed = CGI::Cookie.parse( "page_color=green; domain=localhost; path=/; " + "expires=Mon, 07 May 2007 04:38:18 GMT" ) cookie_hash = Hash[*cookie_parsed.collect{|k,v| [k,v[0]] }.flatten] cookie_hash['name'] = 'page_color' cookie_hash['value'] = cookie_hash[cookie_hash['name']] request.cookies['page_color'] = CGI::Cookie.new(cookie_hash) post :change_color assert_response :success assert cookies['page_color'] assert_equal 'green', cookies['page_color'].value.first end



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.